﻿<Window x:Class="SampleApplication.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:windowsControls="clr-namespace:System.Windows.Controls;assembly=PresentationFramework"
        xmlns:appData="clr-namespace:SampleApplication.Data"
        xmlns:appCommands="clr-namespace:SampleApplication.Commands"
        xmlns:valueConverters="clr-namespace:SampleApplication.Data.ValueConverters"
        xmlns:baseWpfBehaviors="clr-namespace:SwiftMVVM.Behaviors;assembly=SwiftMVVM"
        xmlns:baseWpfControls="clr-namespace:SampleApplication.Controls"
        xmlns:baseWpf="clr-namespace:SampleApplication"
        xmlns:baseWpfCommands="clr-namespace:SwiftMVVM.Commands;assembly=SwiftMVVM"
        xmlns:swiftValueConverters="clr-namespace:SwiftMVVM.ValueConverters;assembly=SwiftMVVM"
        Title="Order Monster" Height="600" Width="700" Style="{DynamicResource windowStyle}" 
        Icon="/SampleApplication;component/Images/cookie.png">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/SampleApplication;component/Resources/GeneralResources.xaml"/>
                <ResourceDictionary Source="/SampleApplication;component/Resources/SplitButtonResources.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <BooleanToVisibilityConverter x:Key="booleanVisibilityConverter"/>
            <Style TargetType="{x:Type baseWpfControls:SplitButton}" BasedOn="{StaticResource ToolBarSplitButtonStyle}"/>
            <swiftValueConverters:MultiValueConverter x:Key="MultiValueConverter"/>
            <valueConverters:IntegerOffsetConverter Offset="1" x:Key="OffsetAdd1"/>
            <swiftValueConverters:EnumEqualsConverter x:Key="EnumEqualsConverter"/>
            <valueConverters:IntegerOffsetConverter Offset="-1" x:Key="OffsetSubtract1"/>
            <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
            <swiftValueConverters:DeltaListToStringConverter x:Key="DeltaListToStringConverter"/>
            <ObjectDataProvider ObjectType="{x:Type appData:OrderManager}" MethodName="Create" x:Key="orderManager"/>
            <ObjectDataProvider x:Key="statesList" ObjectType="{x:Type baseWpf:Utility}" MethodName="CollectionFromEnum">
                <ObjectDataProvider.MethodParameters>
                    <x:Type TypeName="appData:States" />
                </ObjectDataProvider.MethodParameters>
            </ObjectDataProvider>
        </ResourceDictionary>
    </Window.Resources>
    <Grid DataContext="{StaticResource orderManager}">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="auto" />
        </Grid.RowDefinitions>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <ToolBarTray>
                <ToolBarTray.Resources>
                    <Style TargetType="Image" BasedOn="{StaticResource verticalToolbarImageStyle}"/>
                    <Style TargetType="TextBlock" BasedOn="{StaticResource verticalToolbarTextBlockStyle}"/>
                </ToolBarTray.Resources>
                <ToolBar>
                    <Button ToolTip="Saves all changes" 
                        Command="{Binding Source={x:Static appCommands:OrderManagerCommands.SaveChanges}}"
                        CommandParameter="{Binding Path=ChangeManager}">
                        <StackPanel>
                            <Image Source="/SampleApplication;component/Images/table_save.png" />
                            <TextBlock Text="Save"/>
                        </StackPanel>
                    </Button>
                    <Separator/>
                    <baseWpfControls:SplitButton ToolTip="Undo the last change made since the most recent save."
                        CommandParameter="{Binding Path=ChangeManager}"
                        Command="{Binding Source={x:Static baseWpfCommands:ChangeManagerCommands.Undo}}">
                        <baseWpfControls:SplitButton.Content>
                            <StackPanel>
                                <Image Source="/SampleApplication;component/Images/arrow_undo.png"/>
                                <TextBlock Text="Undo"/>
                            </StackPanel>
                        </baseWpfControls:SplitButton.Content>
                        <baseWpfControls:SplitButton.DropDownContextMenu>
                            <ContextMenu>
                                <MenuItem>
                                    <MenuItem.Style>
                                        <Style TargetType="MenuItem">
                                            <Setter Property="Template">
                                                <Setter.Value>
                                                    <ControlTemplate>
                                                        <MenuItem
                                                            Style="{StaticResource headerOverrideMenuItemStyle}" 
                                                            Command="{Binding Source={x:Static baseWpfCommands:ChangeManagerCommands.Undo}}">
                                                            <MenuItem.CommandParameter>
                                                                <MultiBinding Converter="{StaticResource MultiValueConverter}">
                                                                    <MultiBinding.Bindings>
                                                                        <Binding Source="{StaticResource orderManager}" Path="ChangeManager" />
                                                                        <Binding ElementName="undoList" Path="SelectedItems.Count" Mode="OneWay" />
                                                                    </MultiBinding.Bindings>
                                                                </MultiBinding>
                                                            </MenuItem.CommandParameter>
                                                            <MenuItem.Header>
                                                                <Grid>
                                                                    <Grid.RowDefinitions>
                                                                        <RowDefinition Height="*"/>
                                                                        <RowDefinition Height="auto"/>
                                                                    </Grid.RowDefinitions>
                                                                    <ListBox Name="undoList" Width="300"
                                                                         Focusable="False" MinHeight="30" 
                                                                         MaxHeight="100" 
                                                                         baseWpfBehaviors:ListBoxBehavior.AutoSelectOnMouseHover="True"
                                                                         ItemsSource="{Binding Path=ChangeManager.UndoList}"
                                                                         />
                                                                    <Label Grid.Row="1" Background="LightGray"  
                                                                   Content="{Binding ElementName=undoList, Path=SelectedItems.Count, Mode=OneWay}"
                                                                   ContentStringFormat="Undo {0} Actions"/>
                                                                </Grid>
                                                            </MenuItem.Header>
                                                        </MenuItem>
                                                    </ControlTemplate>
                                                </Setter.Value>
                                            </Setter>
                                        </Style>
                                    </MenuItem.Style>
                                </MenuItem>
                            </ContextMenu>
                        </baseWpfControls:SplitButton.DropDownContextMenu>
                    </baseWpfControls:SplitButton>
                    <baseWpfControls:SplitButton ToolTip="Redo the last undone change" 
                        CommandParameter="{Binding Path=ChangeManager}"
                        Command="{Binding Source={x:Static baseWpfCommands:ChangeManagerCommands.Redo}}">
                        <baseWpfControls:SplitButton.Content>
                            <StackPanel>
                                <Image Source="/SampleApplication;component/Images/arrow_redo.png"/>
                                <TextBlock Text="Redo"/>
                            </StackPanel>
                        </baseWpfControls:SplitButton.Content>
                        <baseWpfControls:SplitButton.DropDownContextMenu>
                            <ContextMenu>
                                <MenuItem>
                                    <MenuItem.Style>
                                        <Style TargetType="MenuItem">
                                            <Setter Property="Template">
                                                <Setter.Value>
                                                    <ControlTemplate>
                                                        <MenuItem
                                                            Style="{StaticResource headerOverrideMenuItemStyle}" 
                                                            Command="{Binding Source={x:Static baseWpfCommands:ChangeManagerCommands.Redo}}">
                                                            <MenuItem.CommandParameter>
                                                                <MultiBinding Converter="{StaticResource MultiValueConverter}">
                                                                    <MultiBinding.Bindings>
                                                                        <Binding Source="{StaticResource orderManager}" Path="ChangeManager" />
                                                                        <Binding ElementName="redoList" Path="SelectedItems.Count" Mode="OneWay" />
                                                                    </MultiBinding.Bindings>
                                                                </MultiBinding>
                                                            </MenuItem.CommandParameter>
                                                            <MenuItem.Header>
                                                                <Grid>
                                                                    <Grid.RowDefinitions>
                                                                        <RowDefinition Height="*"/>
                                                                        <RowDefinition Height="auto"/>
                                                                    </Grid.RowDefinitions>
                                                                    <ListBox Name="redoList" Width="300"
                                                                         Focusable="False" MinHeight="30" 
                                                                         MaxHeight="100" 
                                                                         baseWpfBehaviors:ListBoxBehavior.AutoSelectOnMouseHover="True"
                                                                         ItemsSource="{Binding Path=ChangeManager.RedoList}"
                                                                         />
                                                                    <Label Grid.Row="1" Background="LightGray"  
                                                                   Content="{Binding ElementName=redoList, Path=SelectedItems.Count, Mode=OneWay}"
                                                                   ContentStringFormat="Redo {0} Actions"/>
                                                                </Grid>
                                                            </MenuItem.Header>
                                                        </MenuItem>
                                                    </ControlTemplate>
                                                </Setter.Value>
                                            </Setter>
                                        </Style>
                                    </MenuItem.Style>
                                </MenuItem>
                            </ContextMenu>
                        </baseWpfControls:SplitButton.DropDownContextMenu>
                    </baseWpfControls:SplitButton>
                    <Separator/>
                    <Button ToolTip="Add a randomized order" 
                        Command="{Binding Source={x:Static appCommands:OrderManagerCommands.AddOrder}}"
                        CommandParameter="{Binding}">
                        <StackPanel>
                            <Image Source="/SampleApplication;component/Images/add.png" />
                            <TextBlock Text="New Order"/>
                        </StackPanel>
                    </Button>
                    <Button ToolTip="Delete the selected order"
                        Command="{Binding Source={x:Static baseWpfCommands:CollectionViewCommands.RemoveCurrentItem}}"
                        CommandParameter="{Binding Orders}">
                        <StackPanel>
                            <Image Source="/SampleApplication;component/Images/delete.png" />
                            <TextBlock Text="Delete Order"/>
                        </StackPanel>
                    </Button>
                    <Separator/>
                    <Button ToolTip="Increase the weight of the order, max 15." 
                        Command="{Binding Source={x:Static appCommands:OrderManagerCommands.IncreaseOrderWeight}}"
                        CommandParameter="{Binding Orders/}">
                        <StackPanel>
                            <Image Source="/SampleApplication;component/Images/arrow_up.png" />
                            <TextBlock Text="Increase Weight"/>
                        </StackPanel>
                    </Button>
                    <Button ToolTip="Decrease the weight of the order, min 5."
                        Command="{Binding Source={x:Static appCommands:OrderManagerCommands.DecreaseOrderWeight}}"
                        CommandParameter="{Binding Orders/}">
                        <StackPanel>
                            <Image Source="/SampleApplication;component/Images/arrow_down.png" />
                            <TextBlock Text="Decrease Weight"/>
                        </StackPanel>
                    </Button>
                    <ToggleButton IsChecked="{Binding LockOrderWeightAdjustments}">
                        <StackPanel>
                            <StackPanel.Style>
                                <Style TargetType="StackPanel">
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding LockOrderWeightAdjustments}" Value="false">
                                            <Setter Property="ToolTip" Value="Lock Order Weight Changes"/>
                                        </DataTrigger>
                                    </Style.Triggers>
                                    <Setter Property="ToolTip" Value="Unlock Order Weight Changes"/>
                                </Style>
                            </StackPanel.Style>
                            <Image>
                                <Image.Style>
                                    <Style TargetType="Image">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding LockOrderWeightAdjustments}" Value="false">
                                                <Setter Property="Source" Value="/SampleApplication;component/Images/lock_open.png"/>
                                            </DataTrigger>
                                        </Style.Triggers>
                                        <Setter Property="Source" Value="/SampleApplication;component/Images/lock.png"/>
                                    </Style>
                                </Image.Style>
                            </Image>
                            <TextBlock Text="Order Weight"/>
                        </StackPanel>
                    </ToggleButton>
                </ToolBar>
                <ToolBar Band="1">
                    <ToolBar.Resources>
                        <Style TargetType="TextBlock" BasedOn="{StaticResource {x:Type TextBlock}}">
                            <Setter Property="VerticalAlignment" Value="Center"/>
                            <Setter Property="Margin" Value="2"/>
                        </Style>
                    </ToolBar.Resources>
                    <Button ToolTip="Move to the first record" 
                        Command="{Binding Source={x:Static baseWpfCommands:CollectionViewCommands.MoveFirst}}"
                        CommandParameter="{Binding Orders}">
                        <Button.Content>
                            <StackPanel>
                                <Image Source="/SampleApplication;component/Images/resultset_first.png" />
                                <TextBlock Text="First"/>
                            </StackPanel>
                        </Button.Content>
                    </Button>
                    <Button ToolTip="Move to the previous record" 
                        Command="{Binding Source={x:Static baseWpfCommands:CollectionViewCommands.MovePrevious}}"
                        CommandParameter="{Binding Orders}">
                        <Button.Content>
                            <StackPanel>
                                <Image Source="/SampleApplication;component/Images/resultset_previous.png" />
                                <TextBlock Text="Prev"/>
                            </StackPanel>
                        </Button.Content>
                    </Button>
                    <TextBox Name="currentPosition" BorderBrush="{StaticResource controlBorderBrush}" 
                             Margin="2" Width="30" MaxWidth="30" >
                        <TextBox.Text>
                            <Binding Path="Orders.CurrentPosition" Mode="OneWay" Converter="{StaticResource OffsetAdd1}"/>
                        </TextBox.Text>
                    </TextBox>
                    <TextBlock Text="{Binding Orders.Count, StringFormat=of 0}"/>
                    <Button ToolTip="Move to the next record" 
                        Command="{Binding Source={x:Static baseWpfCommands:CollectionViewCommands.MoveNext}}"
                        CommandParameter="{Binding Orders}">
                        <Button.Content>
                            <StackPanel>
                                <Image Source="/SampleApplication;component/Images/resultset_Next.png" />
                                <TextBlock Text="Next"/>
                            </StackPanel>
                        </Button.Content>
                    </Button>
                    <Button ToolTip="Move to the last record" 
                        Command="{Binding Source={x:Static baseWpfCommands:CollectionViewCommands.MoveLast}}"
                        CommandParameter="{Binding Orders}">
                        <Button.Content>
                            <StackPanel>
                                <Image Source="/SampleApplication;component/Images/resultset_last.png" />
                                <TextBlock Text="Last"/>
                            </StackPanel>
                        </Button.Content>
                    </Button>
                    <Button ToolTip="Positions to the ordinal specified in the current position box" 
                        Command="{Binding Source={x:Static baseWpfCommands:CollectionViewCommands.MoveToPosition}}">
                        <Button.CommandParameter>
                            <MultiBinding Converter="{StaticResource MultiValueConverter}">
                                <MultiBinding.Bindings>
                                    <Binding Path="Orders"/>
                                    <Binding ElementName="currentPosition" Path="Text" 
                                                UpdateSourceTrigger="PropertyChanged" 
                                             Converter="{StaticResource OffsetSubtract1}"/>

                                </MultiBinding.Bindings>
                            </MultiBinding>
                        </Button.CommandParameter>
                        <Button.Content>
                            <StackPanel>
                                <Image Source="/SampleApplication;component/Images/find.png" />
                                <TextBlock Text="Find"/>
                            </StackPanel>
                        </Button.Content>
                    </Button>
                </ToolBar>
                <ToolBar Band="1">
                    <TextBlock Text="Per lb"/>
                    <TextBox ToolTip="Base Price of the Order by the Pound" BorderBrush="{StaticResource controlBorderBrush}" 
                             Margin="2" Width="50" MaxWidth="50" 
                             Text="{Binding PricePerPound, StringFormat=C, UpdateSourceTrigger=PropertyChanged}"/>
                    <Separator/>
                    <RadioButton ToolTip="No Changes To Order Will Be Applied" Height="35" Width="25" GroupName="priceMultiplerSingle" IsChecked="{Binding PriceMultiplier, 
                        Converter={StaticResource EnumEqualsConverter},
                        ConverterParameter=Single}">
                        <TextBlock Text="1X"/>
                    </RadioButton>
                    <RadioButton ToolTip="Multiplies the order price by 2" Height="35" Width="25" GroupName="priceMultiplerDouble" IsChecked="{Binding PriceMultiplier, 
                        Converter={StaticResource EnumEqualsConverter},
                        ConverterParameter=Double}">
                        <TextBlock Text="2X"/>
                    </RadioButton>
                    <RadioButton ToolTip="Multiplies the order price by 3" Height="35" Width="25" GroupName="priceMultiplerTriple" IsChecked="{Binding PriceMultiplier, 
                        Converter={StaticResource EnumEqualsConverter},
                        ConverterParameter=Triple}">
                        <TextBlock Text="3X"/>
                    </RadioButton>
                </ToolBar>
                <ToolBar Band="1">
                    <ToggleButton IsChecked="True" Name="chkDisplayStatus" >
                        <StackPanel>
                            <StackPanel.Style>
                                <Style TargetType="StackPanel">
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=ToggleButton}, Path=IsChecked}" Value="false">
                                            <Setter Property="ToolTip" Value="Show Status Bar"/>
                                        </DataTrigger>
                                    </Style.Triggers>
                                    <Setter Property="ToolTip" Value="Hide Status Bar"/>
                                </Style>
                            </StackPanel.Style>
                            <Image Source="/SampleApplication;component/Images/date.png" />
                            <TextBlock Text="Status Bar"/>
                        </StackPanel>
                    </ToggleButton>
                    <Separator/>
                    <ToggleButton Name="chkDisplayDebugBar">
                        <StackPanel>
                            <StackPanel.Style>
                                <Style TargetType="StackPanel">
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=ToggleButton}, Path=IsChecked}" Value="false">
                                            <Setter Property="ToolTip" Value="Show Debug Tools"/>
                                        </DataTrigger>
                                    </Style.Triggers>
                                    <Setter Property="ToolTip" Value="Hide Debug Tools"/>
                                </Style>
                            </StackPanel.Style>
                            <Image Source="/SampleApplication;component/Images/application_view_columns.png" />
                            <TextBlock Text="Log Options"/>
                        </StackPanel>
                    </ToggleButton>
                </ToolBar>
                <ToolBar Band="2" Visibility="{Binding ElementName=chkDisplayDebugBar, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}">
                    <RadioButton IsChecked="{Binding ChangeManager.DeltaMode, 
                        Converter={StaticResource EnumEqualsConverter},
                        ConverterParameter=Normal}">
                        <RadioButton.Triggers>
                            <EventTrigger RoutedEvent="Button.Click">
                                <BeginStoryboard>
                                    <Storyboard TargetName="logTabItem">
                                        <BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="IsSelected" Duration="0:0:0">
                                            <BooleanAnimationUsingKeyFrames.KeyFrames>
                                                <DiscreteBooleanKeyFrame KeyTime="0:0:0" Value="True"/>
                                            </BooleanAnimationUsingKeyFrames.KeyFrames>
                                        </BooleanAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard>
                            </EventTrigger>
                        </RadioButton.Triggers>
                        <StackPanel>
                            <Image Source="/SampleApplication;component/Images/page_delete.png" />
                            <TextBlock Text="Normal"/>
                        </StackPanel>
                    </RadioButton>
                    <RadioButton IsChecked="{Binding ChangeManager.DeltaMode, 
                        Converter={StaticResource EnumEqualsConverter},
                        ConverterParameter=Verbose}">
                        <RadioButton.Triggers>
                            <EventTrigger RoutedEvent="Button.Click">
                                <BeginStoryboard>
                                    <Storyboard TargetName="logTabItem">
                                        <BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="IsSelected" Duration="0:0:0">
                                            <BooleanAnimationUsingKeyFrames.KeyFrames>
                                                <DiscreteBooleanKeyFrame KeyTime="0:0:0" Value="True"/>
                                            </BooleanAnimationUsingKeyFrames.KeyFrames>
                                        </BooleanAnimationUsingKeyFrames>
                                    </Storyboard>
                                </BeginStoryboard>
                            </EventTrigger>
                        </RadioButton.Triggers>
                        <StackPanel>
                            <Image Source="/SampleApplication;component/Images/page_add.png" />
                            <TextBlock Text="Verbose"/>
                        </StackPanel>
                    </RadioButton>
                </ToolBar>
            </ToolBarTray>
            <Grid Grid.Row="1">
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" />
                    <RowDefinition Height="auto" />
                </Grid.RowDefinitions>
                <TabControl Name="mainTab" Background="Transparent">
                    <TabItem Header="Orders">
                        <windowsControls:DataGrid 
                            DataContext="{Binding Orders}"
                            baseWpfBehaviors:DataGridBehavior.AutoScrollCurrentRowIntoView="True"     
                            IsReadOnly="False"
                            ItemsSource="{Binding}" 
                            AutoGenerateColumns="False"
                            IsSynchronizedWithCurrentItem="True" 
                            SelectionUnit="FullRow">
                            <windowsControls:DataGrid.Resources>
                                <Style x:Key="statesComboStyle" TargetType="ComboBox">
                                    <Setter Property="ItemTemplate">
                                        <Setter.Value>
                                            <DataTemplate>
                                                <TextBlock Text="{Binding Path=Name, Mode=OneTime}"/>
                                            </DataTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </windowsControls:DataGrid.Resources>
                            <windowsControls:DataGrid.Columns>
                                <windowsControls:DataGridTemplateColumn Header="Date Baked">
                                    <windowsControls:DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding Path=DateBaked, StringFormat=MM/dd/yyyy}"/>
                                        </DataTemplate>
                                    </windowsControls:DataGridTemplateColumn.CellTemplate>
                                    <windowsControls:DataGridTemplateColumn.CellEditingTemplate>
                                        <DataTemplate>
                                            <DatePicker SelectedDate="{Binding Path=DateBaked}"/>
                                        </DataTemplate>
                                    </windowsControls:DataGridTemplateColumn.CellEditingTemplate>
                                </windowsControls:DataGridTemplateColumn>
                                <windowsControls:DataGridTextColumn Header="Order Type" 
                                           Binding="{Binding Name}" />
                                <windowsControls:DataGridTextColumn Header="Weight" 
                                           Binding="{Binding Weight, Mode=OneWay, StringFormat=0 lbs}"/>
                                <windowsControls:DataGridTextColumn Header="Price" 
                                           Binding="{Binding Price, Mode=OneWay, StringFormat=C}"/>
                                <windowsControls:DataGridComboBoxColumn Header="Destination"  
                                        ItemsSource="{Binding Source={StaticResource statesList}}" 
                                        SelectedValuePath="Value" 
                                        SelectedValueBinding="{Binding DestinationState}"
                                        EditingElementStyle="{StaticResource statesComboStyle}"
                                        ElementStyle="{StaticResource statesComboStyle}"/>
                            </windowsControls:DataGrid.Columns>
                        </windowsControls:DataGrid>
                    </TabItem>
                    <TabItem Name="logTabItem">
                        <TabItem.Header>
                            <TextBlock>
                                <TextBlock.Style>
                                    <Style TargetType="TextBlock" BasedOn="{StaticResource {x:Type TextBlock}}">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding ChangeManager.DeltaList.Count, Mode=OneWay}" Value="0">
                                                <Setter Property="Text" Value="Log (No Changes)"/>
                                            </DataTrigger>
                                        </Style.Triggers>
                                        <Setter Property="Text" Value="{Binding ChangeManager.DeltaList.Count, Mode=OneWay, StringFormat=Log (0 Changes)}"/>
                                    </Style>
                                </TextBlock.Style>
                            </TextBlock>
                        </TabItem.Header>
                        <TextBox baseWpfBehaviors:TextBoxBehavior.AutoScrollToEnd="True" IsReadOnly="True" VerticalScrollBarVisibility="Auto" Width="auto" >
                            <TextBox.Style>
                                <Style TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding ElementName=logTabItem, Path=IsSelected}" Value="True">
                                            <!--The DeltaList is expensive, I only want to Bind to it when the LogTab is selected-->
                                            <Setter Property="Text" Value="{Binding ChangeManager.DeltaList, Mode=OneWay, Converter={StaticResource DeltaListToStringConverter}}"/>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </TextBox.Style>
                        </TextBox>
                    </TabItem>
                </TabControl>
                <Grid Margin="0,5,0,5" Grid.Row="1">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <Label Content="Active Order" Style="{StaticResource headerStyle}"/>
                    <Grid DataContext="{Binding Orders/}"  Grid.Row="1">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="auto" />
                            <ColumnDefinition Width="auto" />
                            <ColumnDefinition Width="10" />
                            <ColumnDefinition Width="auto" />
                            <ColumnDefinition Width="auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="auto" />
                            <RowDefinition Height="auto" />
                            <RowDefinition Height="auto" />
                            <RowDefinition Height="auto" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <Label Content="Type"/>
                        <TextBox Grid.Column="1" Text="{Binding Name, UpdateSourceTrigger=PropertyChanged}"/>
                        <Label Grid.Row="1" Content="Weight"/>
                        <TextBox Grid.Row="1" Grid.Column="1" >
                            <TextBox.Style>
                                <Style TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding Parent.LockOrderWeightAdjustments}" Value="True">
                                            <Setter Property="IsEnabled" Value="False"/>
                                            <Setter Property="Text">
                                                <Setter.Value>
                                                    <Binding Path="Weight" StringFormat="0 Pounds" />
                                                </Setter.Value>
                                            </Setter>
                                        </DataTrigger>
                                    </Style.Triggers>
                                    <Setter Property="IsEnabled" Value="True"/>
                                    <Setter Property="Text">
                                        <Setter.Value>
                                            <Binding Path="Weight" UpdateSourceTrigger="PropertyChanged" ValidatesOnDataErrors="True"/>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </TextBox.Style>
                        </TextBox>
                        <Label Grid.Column="3" Content="Price"/>
                        <TextBox IsReadOnly="True" Grid.Column="4" Text="{Binding Price, Mode=OneWay, StringFormat=C}"/>
                        <Label Grid.Column="3" Grid.Row="1" Content="Destination"/>
                        <ComboBox Grid.Column="4" Grid.Row="1" 
                                  ItemsSource="{Binding Source={StaticResource statesList}, Mode=OneTime}" 
                                  SelectedValuePath="Value" 
                                  SelectedValue="{Binding DestinationState}" >
                            <ComboBox.ItemTemplate>
                                <!--Defining the ItemTemplate allows us to bind to 
                                objects that do not implement INotifyPropertyChanged-->
                                <DataTemplate>
                                    <TextBlock Text="{Binding Path=Name, Mode=OneTime}"/>
                                </DataTemplate>
                            </ComboBox.ItemTemplate>
                        </ComboBox>

                    </Grid>
                </Grid>
            </Grid>
        </Grid>
        <StatusBar Grid.Row="1" Visibility="{Binding ElementName=chkDisplayStatus, Path=IsChecked, Converter={StaticResource booleanVisibilityConverter}}">
            <StatusBarItem Content="Status:"/>
            <StatusBarItem Content="{Binding Orders.Count}" ContentStringFormat="0 orders"/>
            <StatusBarItem>
                <StackPanel Orientation="Horizontal">
                    <Image VerticalAlignment="Center" Height="12" Source="/SampleApplication;component/Images/sum.png" />
                    <TextBlock Text="{Binding TotalPrice, StringFormat=C}"/>
                </StackPanel>
            </StatusBarItem>
            <StatusBarItem HorizontalAlignment="Right">
                <StackPanel Orientation="Horizontal">
                    <StatusBarItem>
                        <Image Height="12">
                            <Image.Style>
                                <Style TargetType="Image">
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding LockOrderWeightAdjustments}" Value="false">
                                            <Setter Property="Source" Value="/SampleApplication;component/Images/lock_open.png"/>
                                        </DataTrigger>
                                    </Style.Triggers>
                                    <Setter Property="Source" Value="/SampleApplication;component/Images/lock.png"/>
                                </Style>
                            </Image.Style>
                        </Image>
                    </StatusBarItem>
                    <StatusBarItem>
                        <StatusBarItem.Style>
                            <Style TargetType="StatusBarItem" BasedOn="{StaticResource {x:Type StatusBarItem}}">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding LockOrderWeightAdjustments}" Value="false">
                                        <Setter Property="Content" Value="Weight edits are allowed"/>
                                    </DataTrigger>
                                </Style.Triggers>
                                <Setter Property="Content" Value="Weight edits are not allowed"/>
                            </Style>
                        </StatusBarItem.Style>
                    </StatusBarItem>
                </StackPanel>
            </StatusBarItem>
        </StatusBar>
    </Grid>
</Window>

